import selenium.webdriver as webdriver
import time

from selenium.webdriver.support.select import Select


class addnewuser:
    def __init__(self):
        wd=webdriver.Firefox()
        wd.maximize_window()
        wd.get("http://192.168.4.225/TinyShop2.4/index.php?con=admin&act=login")
        wd.implicitly_wait(5)
        self.wd=wd
    def login(self):
        wd=self.wd
        wd.find_element_by_name("name").send_keys("admin")
        wd.find_element_by_name("password").send_keys("123456")
        wd.find_element_by_name("verifyCode").send_keys("aaaa")
        wd.find_element_by_css_selector("input.button").click()
    def addnewuser(self,li):
        wd=self.wd
        wd.find_element_by_link_text("客户中心").click()
        wd.find_element_by_link_text("添加").click()
        wd.find_element_by_name("name").send_keys(li[0])
        wd.find_element_by_name("password").send_keys(li[1])
        wd.find_element_by_name("repassword").send_keys(li[2])
        wd.find_element_by_name("email").send_keys(li[3])
        wd.find_element_by_name("real_name").send_keys(li[4])
        wd.find_element_by_name("birthday").send_keys(li[5])
        a1=wd.find_element_by_id("province")
        Select(a1).select_by_index(li[6])
        a2=wd.find_element_by_id("city")
        Select(a2).select_by_index(li[7])
        a3=wd.find_element_by_id("county")
        Select(a3).select_by_index(li[8])
        wd.find_element_by_name("addr").send_keys(li[9])
        wd.find_element_by_name("phone").send_keys(li[10])
        wd.find_element_by_name("mobile").send_keys(li[11])
        wd.find_element_by_name("point").clear()
        wd.find_element_by_name("point").send_keys(li[12])
        wd.find_element_by_css_selector("input.button").click()
        # try:
        #     m=wd.find_element_by_id("message-bar").text
        #     if "用户名或邮箱已经存在" in m:
        #         print("测试通过")
        #     else:
        #         print("测试失败")
        # except:
        #     try:
        #         x=wd.find_element_by_class_name("invalid-msg").text
        #         print(x)
        #         if "密码必需大于6位" in x:
        #             print("测试通过")
        #         else:
        #             print("测试失败")
        #     except:
        #         print("测试通过")





if __name__=="__main__":
    a=adduser()
    a.login()
    a.addnewuser()